//
//  CertPersonIdentifyCode.m
//  TestProject
//
//  Created by 武侠 on 2022/2/21.
//  Copyright © 2022 zhulong. All rights reserved.
//

#import "CertPersonIdentifyCode.h"
#import "CertTLV.h"

@implementation CertPersonIdentifyCode

- (NSDictionary<NSNumber *,NSString *> *)objectType {
    return @{
        @(0x80) : @"residenterCardNumber",
        @(0x81) : @"militaryOfficerCardNumber",
        @(0x82) : @"passportNumber"
    };
}

- (id)getObject:(NSData *)data type:(uint16_t)type {
    char *sdata = (char *)data.bytes;
    CertItemLength *length = [[CertItemLength alloc] initWithData:sdata index:1];
    if (type == 0x80 || type == 0x82) {
        return [CertTLV uasciiStringFromValue:sdata begin:0 length:length];
    } else if (type == 0x81) {
        return [CertTLV utf8StringFromValue:sdata begin:0 length:length];
    }
    return [super getObject:data type:type];
}

- (NSString *)description {
    NSMutableString *str = [NSMutableString string];
    if (self.residenterCardNumber != nil) {
        [str appendFormat:@"CardNumber(身份证号码):%@\n", self.residenterCardNumber];
    }
    if (self.militaryOfficerCardNumber != nil) {
        [str appendFormat:@"militaryOfficerCardNumber(军官证号码):%@\n", self.militaryOfficerCardNumber];
    }
    if (self.passportNumber != nil) {
        [str appendFormat:@"passportNumber(护照号码):%@\n", self.passportNumber];
    }
    if (str.length > 0) {
        [str deleteCharactersInRange:NSMakeRange(str.length-1, 1)];
    }
    return str;
}

@end
